﻿using System.Collections.Generic;
using ACompany.OrderProcessing.Infrastructure;
using ACompany.OrderProcessing.Model;
using NUnit.Framework;

[TestFixture()]
public class ProductTests
{

    [Test()]
    public void A_Product_Has_A_Broken_Business_Rule_If_Stock_Is_A_Negative_Figure()
    {
        Product aProduct = new Product();
        aProduct.Name = "Hat";
        aProduct.Price = 33.99M;
        aProduct.Stock = -9;

        Assert.IsTrue(ContainsBrokenRules("Stock cannot be a negative number", aProduct.GetBrokenRules()));
    }

    [Test()]

    public void A_Product_Has_A_Broken_Business_Rule_If_Its_Name_Is_Over_50_Chars()
    {
        Product aProduct = new Product();
        aProduct.Name = "Hatsfgdfgdfgdfgdfgdfgdgdfgdfgdfgdfgdfgdfdggdfggfgdfggfddfgdfg";
        aProduct.Price = 33.99M;
        aProduct.Stock = 9;

        Assert.IsTrue(ContainsBrokenRules("Name should be 50 chars or less", aProduct.GetBrokenRules()));
    }

    [Test()]

    public void A_Product_Has_A_Broken_Business_Rule_If_It_Has_No_Name()
    {
        Product aProduct = new Product();
        aProduct.Price = 33.99M;
        aProduct.Stock = 9;

        Assert.IsTrue(ContainsBrokenRules("Name is a required value", aProduct.GetBrokenRules()));
    }

    [Test()]

    public void A_Product_Has_A_Broken_Business_Rule_If_Its_Price_Is_A_Negative_Figure()
    {
        Product aProduct = new Product();
        aProduct.Name = "Hat";
        aProduct.Price = -33.99M;
        aProduct.Stock = 1;

        Assert.IsTrue(ContainsBrokenRules("Price cannot be a negative number", aProduct.GetBrokenRules()));
    }

    [Test()]

    public void A_Product_Is_Valid_If_It_Has_A_Price_Name_And_Stock()
    {
        Product aProduct = new Product();
        aProduct.Name = "Hat";
        aProduct.Price = 33.99M;
        aProduct.Stock = 1;

        Assert.AreEqual(0, aProduct.GetBrokenRules().Count);
    }

    private bool ContainsBrokenRules(string ExpectedBrokeRule, IList<BrokenRule> ListOFBrokenRules)
    {

        foreach (BrokenRule brokenRule in ListOFBrokenRules)
        {
            if (ExpectedBrokeRule == brokenRule.Rule)
            {
                return true;
            }
        }

        return false;

    }

}